package com.saas.tenant.tenantConfig;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @auther Jiang Tian
 * @date 2025/2/27
 * @apiNote
 **/
@Component
public class MyTenantLineHandler implements TenantLineHandler {

    @Autowired
    TenantProperties properties;

    @Override
    public Expression getTenantId() {
        return new LongValue(TenantContextHolder.getTenantId());
    }

    @Override
    public String getTenantIdColumn() {
        return properties.getColumn();
    }

    @Override
    public boolean ignoreTable(String tableName) {
        return properties.getExclusionTable().stream().anyMatch(t -> t.equalsIgnoreCase(tableName));
    }

}
